package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.*;
import com.smile.model.request.*;
import com.smile.service.PayloadService;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/payload")
public class PayloadController {

    @Autowired
    private PayloadService payloadService;

    /**
     * 负载控制权抢夺
     *
     * @param payloadAuthorityGrabRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/payloadAuthorityGrab")
    public R<Void> payloadAuthorityGrab(@RequestBody PayloadAuthorityGrabRequest payloadAuthorityGrabRequest) throws MqttException {
        PayloadAuthorityGrabRequestDTO payloadAuthorityGrabRequestDTO = BeanUtil.copyProperties(payloadAuthorityGrabRequest, PayloadAuthorityGrabRequestDTO.class);
        payloadService.payloadAuthorityGrab(payloadAuthorityGrabRequestDTO);
        return R.ok();
    }

    /**
     * 开始拍照
     *
     * @return
     */
    @PostMapping("/cameraPhotoTake")
    public R<Void> cameraPhotoTake(@RequestBody CameraPhotoTakeRequest cameraPhotoTakeRequest) throws MqttException {
        CameraPhotoTakeRequestDTO cameraPhotoTakeRequestDTO = BeanUtil.copyProperties(cameraPhotoTakeRequest, CameraPhotoTakeRequestDTO.class);
        payloadService.cameraPhotoTake(cameraPhotoTakeRequestDTO);

        return R.ok();
    }

    /**
     * 停止拍照
     *
     * @return
     */
    @PostMapping("/cameraPhotoStop")
    public R<Void> cameraPhotoStop(@RequestBody CameraPhotoStopRequest cameraPhotoStopRequest) throws MqttException {
        CameraPhotoStopRequestDTO cameraPhotoStopRequestDTO = BeanUtil.copyProperties(cameraPhotoStopRequest, CameraPhotoStopRequestDTO.class);
        payloadService.cameraPhotoStop(cameraPhotoStopRequestDTO);
        return R.ok();
    }

    /**
     * 开始摄像
     *
     * @return
     */
    @PostMapping("/cameraRecordingStart")
    public R<Void> cameraRecordingStart(@RequestBody CameraRecordStartRequest cameraRecordStartRequest) throws MqttException {
        CameraRecordStartRequestDTO cameraRecordStartRequestDTO = BeanUtil.copyProperties(cameraRecordStartRequest, CameraRecordStartRequestDTO.class);
        payloadService.cameraRecordingStart(cameraRecordStartRequestDTO);
        return R.ok();
    }

    /**
     * 停止摄像
     */
    @PostMapping("/cameraRecordingStop")
    public R<Void> cameraRecordingStop(@RequestBody CameraRecordStopRequest cameraRecordStopRequest) throws MqttException {
        CameraRecordStopRequestDTO cameraRecordStopRequestDTO = BeanUtil.copyProperties(cameraRecordStopRequest, CameraRecordStopRequestDTO.class);
        payloadService.cameraRecordingStop(cameraRecordStopRequestDTO);
        return R.ok();
    }

    /**
     * 分屏
     */
    @PostMapping("/cameraScreenSplit")
    public R<Void> cameraScreenSplit(@RequestBody CameraRecordStopRequest cameraRecordStopRequest) throws MqttException {
        CameraRecordStopRequestDTO cameraRecordStopRequestDTO = BeanUtil.copyProperties(cameraRecordStopRequest, CameraRecordStopRequestDTO.class);
        payloadService.cameraRecordingStop(cameraRecordStopRequestDTO);
        return R.ok();
    }


    /**
     * 切换相机模式
     *
     * @param cameraModeSwitchRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/cameraModeSwitch")
    public R<Void> cameraModeSwitch(@RequestBody CameraModeSwitchRequest cameraModeSwitchRequest) throws MqttException {
        CameraModeSwitchRequestDTO cameraModeSwitchRequestDTO = BeanUtil.copyProperties(cameraModeSwitchRequest, CameraModeSwitchRequestDTO.class);
        payloadService.cameraModeSwitch(cameraModeSwitchRequestDTO);
        return R.ok();
    }

    /**
     * 视频存储设置
     *
     * @param videoStorageSetRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/videoStorageSet")
    public R<Void> videoStorageSet(@RequestBody VideoStorageSetRequest videoStorageSetRequest) throws MqttException {
        VideoStorageSetRequestDTO videoStorageSetRequestDTO = BeanUtil.copyProperties(videoStorageSetRequest, VideoStorageSetRequestDTO.class);
        payloadService.videoStorageSet(videoStorageSetRequestDTO);
        return R.ok();
    }

    /**
     * 更改照片存储设置
     *
     * @param photoStorageSetRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/photoStorageSet")
    public R<Void> photoStorageSet(@RequestBody PhotoStorageSetRequest photoStorageSetRequest) throws MqttException {
        PhotoStorageSetRequestDTO photoStorageSetRequestDTO = BeanUtil.copyProperties(photoStorageSetRequest, PhotoStorageSetRequestDTO.class);
        payloadService.photoStorageSet(photoStorageSetRequestDTO);
        return R.ok();
    }

    /**
     * 重置云台
     *
     * @param gimbalResetRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/gimbalReset")
    public R<Void> gimbalReset(@RequestBody GimbalResetRequest gimbalResetRequest) throws MqttException {
        GimbalResetRequestDTO gimbalResetRequestDTO = BeanUtil.copyProperties(gimbalResetRequest, GimbalResetRequestDTO.class);
        payloadService.gimbalReset(gimbalResetRequestDTO);
        return R.ok();
    }
    /**
     * 变焦
     *
     * @param cameraFocalLengthSetRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/cameraFocalLengthSet")
    public R<Void> cameraFocalLengthSet(@RequestBody CameraFocalLengthSetRequest cameraFocalLengthSetRequest) throws MqttException {
        CameraFocalLengthSetRequestDTO cameraFocalLengthSetRequestDTO = BeanUtil.copyProperties(cameraFocalLengthSetRequest, CameraFocalLengthSetRequestDTO.class);
        payloadService.cameraFocalLengthSet(cameraFocalLengthSetRequestDTO);
        return R.ok();
    }

    /**
     * 画面拖动控制
     *
     * @param cameraScreenDragRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/cameraScreenDrag")
    public R<Void> cameraScreenDrag(@RequestBody CameraScreenDragRequest cameraScreenDragRequest) throws MqttException {
        CameraScreenDragRequestDTO cameraScreenDragRequestDTO = BeanUtil.copyProperties(cameraScreenDragRequest, CameraScreenDragRequestDTO.class);
        payloadService.cameraScreenDrag(cameraScreenDragRequestDTO);
        return R.ok();
    }

    /**
     * 框选变焦
     *
     * @param cameraFrameZoomRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/cameraFrameZoom")
    public R<Void> cameraFrameZoom(@RequestBody CameraFrameZoomRequest cameraFrameZoomRequest) throws MqttException {
        CameraFrameZoomRequestDTO cameraFrameZoomRequestDTO = BeanUtil.copyProperties(cameraFrameZoomRequest, CameraFrameZoomRequestDTO.class);
        payloadService.cameraFrameZoom(cameraFrameZoomRequestDTO);
        return R.ok();
    }
}
